<?php
namespace app\index\controller;
header('Access-Control-Allow-Origin:*');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept"); 

class Post extends Base
{
    public function index()
    {
    	$limit = empty($_GET['limit'])?'':$_GET['limit'];
		$post = model('post');
		if($limit == ''){
			$data =$post->select();
		}else{
			$data =$post->limit(0,$limit)->select();
		}
		if($data){
			$info = array(
				'status' => 1,
				'data' =>$data
			);
		}else{
			$info = array(
				'status' => 0,
			);	
		}
		echo json_encode($info);
    }
    public function detail(){
		if(empty($_GET['pid'])){
         		 echo json_encode(array('status'=>1,'info'=>'缺少参数'));
			exit;
		}
    	$pid=$_GET['pid'];  
    	$post=model('post');
    	$homeuser=model('homeuser');
    	$postdata= $post->alias('p')->join('td_homeuser u','p.uid = u.id')->field('p.*,u.username,u.photo')->where(array('p.id'=>$pid))->find();
    	if($postdata){
    		$result=array(
    			'status'=>0,
    			'info'=>$postdata
    		);
    	}else{
    		$result=array(
    			'status'=>1
    		);
    	}
    	echo json_encode($result);
    }
}
